package com.dwsoft.mapper;

import com.dwsoft.pojo.DataKpiDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author sqw
 * @version 1.0
 * @description 数据KPI持久
 * @ClassName IDataKpiMapper
 * @Date 2020/8/4
 * @since jdk1.8
 */
@Mapper
@Repository
public interface IDataKpiMapper {

    /**
     *功能描述 获取所有kpi指标配置信息
     * @author sqw
     * @return java.util.List<com.dwsoft.pojo.DataKpiDO>
     * @throws DataAccessException
     * @date 2020/8/5
     */
    @Select("select kpi_sn     kpiSn,\n" +
            "       kpi_cn     kpiCn,\n" +
            "       kpi_script kpiScript,\n" +
            "       adapter_id adapterId\n" +
            "  from cfg_word_data_kpi")
    public List<DataKpiDO> getKpis() throws DataAccessException;

    /**
     *功能描述 获取所有kpi指标配置信息
     * @author sqw
     * @return java.util.List<com.dwsoft.pojo.DataKpiDO>
     * @throws DataAccessException
     * @date 2020/8/5
     */
    @Select("select kpi_sn     kpiSn,\n" +
            "       kpi_cn     kpiCn,\n" +
            "       kpi_script kpiScript,\n" +
            "       adapter_id adapterId\n" +
            "  from cfg_word_data_kpi where kpi_sn=#{name}")
    public DataKpiDO getKpi(String name) throws DataAccessException;

    /**
     *功能描述 执行SQL脚本
     * @author sqw
     * @param script 脚本
     * @return java.lang.String
     * @throws DataAccessException
     * @date 2020/8/5
     */
    @Select("${script}")
    public String getKpiValueForText(@Param("script") String script) throws DataAccessException;


    /**
     *功能描述 执行SQL脚本
     * @author sqw
     * @param script 脚本
     * @return List<Map<String,Object>>
     * @throws DataAccessException
     * @date 2020/8/5
     */
    @Select("${script}")
    public List<Map<String,String>> getKpiValueForList(@Param("script") String script) throws DataAccessException;
}
